package controller

import (
	"mini-app/internal/app/web/service"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type ShoppingCart struct{}

// 保存购物车
func (ShoppingCart) Save(c *gin.Context) {
	var params struct {
		RobotName string `json:"robot_name"`
		GoodsID   string `json:"goods_id"`
		Count     int    `json:"count"` // 当前数量
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	openid := c.GetString("openid")
	err := service.ShoppingCart{}.Save(c.Request.Context(), openid, params.RobotName, params.GoodsID, params.Count)
	response.JSON(c, nil, err)
}

// 购物车列表
func (ShoppingCart) List(c *gin.Context) {
	var params struct {
		Longitude *float64 `json:"longitude"`
		Latitude  *float64 `json:"latitude"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	openid := c.GetString("openid")
	data, err := service.ShoppingCart{}.List(c.Request.Context(), openid, params.Longitude, params.Latitude)
	response.JSON(c, data, err)
}
